package thinking.in.spring.ioc.bean.lifecycle;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;

/**
 * 注解BeanDefinition 解析示例
 */
public class AnnotatedBeanDefinitionParsingDemo
{

    public static void main(String[] args)
    {
//        AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader();
//        reader.register();

        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(beanFactory);

        int beforeCount = reader.getRegistry().getBeanDefinitionCount();
        reader.registerBean(AnnotatedBeanDefinitionParsingDemo.class);
        int afterCount = reader.getRegistry().getBeanDefinitionCount();
        System.out.printf("已加载 BeanDefinition 数量：%s\n", (afterCount - beforeCount));
        //普通Class 作为Component注册到Spring IOC后，通常Bean名称   annotatedBeanDefinitionParsingDemo

        // Bean  默认名称生成时通过 BeanNameGenerator 注解的时通过AnnotationBeanNameGenerator
        // reader.setBeanNameGenerator();可以替换名字生成器
        AnnotatedBeanDefinitionParsingDemo demo =
                (AnnotatedBeanDefinitionParsingDemo) beanFactory.getBean("annotatedBeanDefinitionParsingDemo");
        System.out.println(demo);
    }
}
